package events

import "errors"

type EventCode int

const (
	Active     EventCode = iota // pipeline active
	InActive                    //pipeline inactive
	Connect                     //channel connect
	Disconnect                  //channel disconnect
	Error
)

// InactiveEvent stands for pipeline InActive event
var InactiveEvent = NewEventWithCode(InActive)

// ActiveEvent stands for pipeline Active event
var ActiveEvent = NewEventWithCode(Active)

// ConnectEvent stands for channel Connect event
var ConnectEvent = NewEventWithCode(Connect)

// DisconnectEvent stands for channel Disconnect event
var DisconnectEvent = NewEventWithCode(Disconnect)

type EventWithCode struct {
	code EventCode
}

func (c *EventWithCode) Is(code EventCode) bool {
	return c.code == code
}

func NewEventWithCode(code EventCode) *EventWithCode {
	return &EventWithCode{code: code}
}

type EventWithError struct {
	error
	EventWithCode
}

func (e *EventWithError) Is(err error) bool {
	return errors.Is(err, e.error)
}

func NewEventWithError(err error) *EventWithError {
	return &EventWithError{error: err, EventWithCode: EventWithCode{
		code: Error,
	}}
}
